﻿
using IBLL;
using IDAL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class ManagerBLL : IManagerBLL
    {
        public ManagerBLL(IBaseDAL<ManagerInfo> dal)
        {
            Dal = dal;
        }

        public IBaseDAL<ManagerInfo> Dal { get; }
        /// <summary>
        /// 账号信息表集合
        /// </summary>
        /// <returns>返回集合</returns>
        public List<ManagerInfo> GetManagers()
        {
            return Dal.GetValues().ToList();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="num">登录账号</param>
        /// <param name="pwd">密码</param>
        /// <returns>返回账号信息表对象</returns>
        public  async Task<ManagerInfo> LoginInfo(string num, string pwd)
        {
            ManagerInfo man = Dal.GetValues().FirstOrDefault(x => x.Loginnum == num);
            if (man == null)
            {
                man = new ManagerInfo() { Mid = -1 };//账号不存在
            }
            else 
            {
                if (pwd != man.Pwd) 
                {
                    man = new ManagerInfo() { Mid = -2 };
                }
                
            }
            return await Task.FromResult(man);
        }
    }
}
